package com.smart.advice;

import com.smart.pojo.ResultBean;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionAdvice {

    @ExceptionHandler({UnknownAccountException.class})
    public ResultBean exceptionHandler1(Exception e) {
        System.out.println("异常类型1：" + e.getClass().getName());
        return ResultBean.error("账号或密码错误");
    }

    @ExceptionHandler({IncorrectCredentialsException.class})
    public ResultBean exceptionHandler3(Exception e) {
        System.out.println("异常类型2：" + e.getClass().getName());
        return ResultBean.error("账号或密码错误");
    }

    @ExceptionHandler({AuthorizationException.class})
    public ResultBean exceptionHandler2(Exception e) {
        return ResultBean.error("对不起，您没有权限执行此操作");
    }
}
